Skip to content

Conversation

roflmaostc
Copy link
Contributor

@roflmaostc roflmaostc commented Jul 31, 2025

Hi,

I noticed we do a reference from insertdims to dropdims but not the other way round.

So I added a similar reference as in dropdims which is added in 1.12 (#45793)

Best,

Felix

@jishnub
Copy link
Member

jishnub commented Jul 31, 2025

I would suggest adding this to the end of the docstring instead of the beginning.

@roflmaostc
Copy link
Contributor Author

roflmaostc commented Jul 31, 2025

I can do, I just wanted to keep it consistent with

help?> insertdims
search: insertdims insert! issetgid issetuid selectdim ndims setdiff insorted istextmime

  insertdims(A; dims)

  Inverse of dropdims; return an array with new singleton dimensions at every dimension in dims.

  Repeated dimensions are forbidden and the largest entry in dims must be less than or equal than ndims(A) +
  length(dims).

  The result shares the same underlying data as A, such that the result is mutable if and only if A is mutable,
  and setting elements of one alters the values of the other.

  See also: dropdims, reshape, vec.

  Examples
  ≡≡≡≡≡≡≡≡

  julia> x = [1 2 3; 4 5 6]
  2×3 Matrix{Int64}:
   1  2  3
   4  5  6
  
  julia> insertdims(x, dims=3)
  2×3×1 Array{Int64, 3}:
  [:, :, 1] =
   1  2  3
   4  5  6
  
  julia> insertdims(x, dims=(1,2,5)) == reshape(x, 1, 1, 2, 3, 1)
  true
  
  julia> dropdims(insertdims(x, dims=(1,2,5)), dims=(1,2,5))
  2×3 Matrix{Int64}:
   1  2  3
   4  5  6

  │ Julia 1.12
  │
  │  Requires Julia 1.12 or later.

@jishnub
Copy link
Member

jishnub commented Jul 31, 2025

I would suggest that the docstring insertdims be changed as well. It should start with a description, and not with a reference to another function that one might not have encountered.

@nsajko nsajko added docs This change adds or pertains to documentation arrays [a, r, r, a, y, s] labels Aug 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s] docs This change adds or pertains to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants